function showDeviceSearch() {
	window.location.href = "showDeviceSearch.do";
}

function ajaxFindDeviceSearchList(currentPage,pageSize) {
	$.ajax({
		type : "post",
		url : "ajaxDeviceSearchList.do",
		data : {
			plateNum : $("#plateNum").val(),
			plateTypeId : $("#licencePlateKind").val(),
			vehicleTypeId : $("#vehicleType").val(),
		    ownername : $("#ownername").val(),
			effectiveStartTime : $("#effectiveStartTime").val(),
			effectiveEndTime : $("#effectiveEndTime").val(),
			currentPage:currentPage,
			pageSize:pageSize,
		},
		success : function(msg) {
			$("#listDeviceBox").html(msg);
		}
	});
}

function ajaxShowDeviceEdit(id){
	$.ajax({
		type:"post",
		url:"ajaxShowDeviceEdit.do",
		data:{deviceId:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 740,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons: [
				          {
				        	  text: "保存",
				        	  click: function() {
				        		  ajaxSaveDevice(this);
				        	  }
				          },
				          {
				        	  text: "关闭",
				        	  click: function() {
				        		  $(this).dialog( "close" );
				        	  }
				          }
				          ]
			});
		}
	});
}

function ajaxSaveDevice(objDialog) {
	deviceValidate();
	if ($("#frmDevice").valid()) {
		$(objDialog).dialog("close");
		var options ={
				type: "post",
				url : "ajaxSaveDevice.do",
				success: function (msg) {
					clearInput("#sltDevice");
					showMessageDialog("保存设备信息","设备信息保存成功。",null,dialogType.info);
					ajaxFindDeviceSearchList();
				}
		};
		$("#frmDevice").ajaxSubmit(options);
	}
}

function ajaxShowDeviceView(id){
	$.ajax({
		type:"post",
		url:"ajaxShowDeviceView.do",
		data:{deviceId:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 740,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons : [ {
					text : "关闭",
					click : function() {
						$(this).dialog("close");
					}
				} ]
			});
		}
	});
}

function ajaxDeleteDeviceById(id) {
	var deviceIds="";
	var sltSC = $("#listDeviceList tbody input:checked").length;
	if(id==null){
		$("#listDeviceList tbody input:checked").each(function(){ 
			deviceIds += $(this).val()+";";
		});
		if(sltSC == 0){
			showMessageDialog("提示","请选择一行或多行",null,dialogType.info);
			return;
		}else{
			deviceIds = deviceIds.substring(0, deviceIds.length-1);
		} 
	}else{
		deviceIds=id;
		sltSC = 1;
	}
	if( deviceIds!=null){
		showMessageDialog("删除设备信息","确定要删除所选“"+sltSC+"”条设备信息记录吗？",
				function () {
			$.ajax({     
				type:"post",
				url:"ajaxDeleteDeviceByIds.do",
				data:{deviceIds:deviceIds},
				success:function(msg){
					ajaxFindDeviceSearchList();
					showMessageDialog("提示","设备信息删除成功",null,dialogType.info);
				}
			});
		}
		,dialogType.warning);
	}
}

function deviceValidate(){
	$("#frmDevice").validate({
		errorLabelContainer: $("#infoDevice"),
		rules : {
			deviceName : {
				required :true				
			},
			deviceType : {
				required :true				
			},
			deviceZCNum : {
				required :true				
			}
		},
		messages : {
			deviceName : {
				required :"请输入设备名称！"
			},
			deviceType : {
				required :"请选择设备类型！"
			},
			deviceZCNum : {
				required :"请输入资产编号！"
			}
		},
		success: function(label) {
			label.html("&nbsp;");
		}
	});
}
